<!doctype html>
<html lang="en">
  <head>
    <title>湖南省主要珍稀植物管理信息系统</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
    <link rel="stylesheet" href="css/common.css">
  </head>
  <script src="./js/allData.js"></script>
  <script src="./js/vue.js"></script>
  <style>
      li a{
          line-height: 50px;
          font-size: 20px;
          color: white;
      }
  </style>
  <body style="background-image: url(img/14.jpg);background-size: 100% 8%;">
    <div id="navigator">
        <a id="systemName" href="index.html" style="color: white;">
            <b>湖南省主要珍稀植物管理信息系统</b>
        </a>
        
    </div>
    <div class="container-fluid pt-3 mt-2">
        <div class="row">
            <div id="nav-side" class="col-md-2 pl-0 ml-0">
                <ul class="nav flex-column navbar-dark pl-0 ml-3" >
                    <!-- 带下拉的导航 -->
                    <li class="nav-item">
                        <a href="index.html" class="nav-link">首页</a>
                    </li>
                    <li class="nav-item">
                        <a href="dynamics.html" class="nav-link">保护动态</a>
                    </li>
                    <li class="nav-item">
                        <a href="policy.html" class="nav-link">政策法规</a>
                    </li>
                    
                    <li class="nav-item dropdown ">
                        <a class="nav-link dropdown-toggle" data-toggle="dropdown" href="#" role="button" aria-haspopup="true" aria-expanded="false">用户管理</a>
                        <div class="dropdown-menu">
                            <a class="dropdown-item" href="user.html">查看用户</a>
                            <a class="dropdown-item" href="adduser.html">添加用户</a>
                        </div>
                    </li>
                    <li class="nav-item dropdown">
                        <a class="nav-link dropdown-toggle" data-toggle="dropdown" href="#" role="button" aria-haspopup="true" aria-expanded="false">植物管理</a>
                        <div class="dropdown-menu">
                            <a class="dropdown-item" href="plant.html">查看植物</a>
                            <div class="dropdown-divider"></div>
                            <a class="dropdown-item" href="addplant.html">添加植物</a>
                        </div>
                    </li>
                </ul>
            </div>

            <div id="app" class="pl-3 ml-3 col-md-9">

                <nav>
                    <a style="position: relative;left: 70%;color: blue;" href="addplant.html">添加湖南省地方重点保护植物</a>
                    <a style="position: relative;left: 72%;color: blue;" href="addnplant.html">添加湖南省国家重点保护植物</a>
                </nav>
               <br>
               <br>
                 <!-- 植物添加 -->
                <form id="form" style="border-radius: 5%;border: none;" method="post" class="pl-5 ml-5 m-3">
                    <!-- 中名-->
                    <div class="form-group row">
                        <label for="middlename" class="offset-md-1 col-md-2 pt-2">植物中名:</label>
                        <input type="text" v-model="nplant.middlename" class="form-control col-md-7" name="middlename" id="middlename" 
                                    aria-describedby="helpId" placeholder="请输入植物中名" style="background-color: transparent;border: 1px solid black;">
                    </div>
                    <!--拉丁名-->
                    <div class="form-group row">
                        <label for="latinname" class="offset-md-1 col-md-2 pt-2">植物拉丁名：</label>
                        <input type="text" v-model="nplant.latinname" class="form-control col-md-7" name="latinname" id="latinname" 
                                       aria-describedby="helpId" placeholder="请输入植物拉丁名" style="background-color: transparent;border: 1px solid black;">
                    </div>

                   <!--科名-->
                   <div class="form-group row">
                    <label for="sectionname" class="offset-md-1 col-md-2 pt-2">植物科名：</label>
                    <input type="text" v-model="nplant.sectionname" class="form-control col-md-7" name="sectionname" id="sectionname" 
                                   aria-describedby="helpId" placeholder="请输入植物科名" style="background-color: transparent;border: 1px solid black;">
                   </div>

                    <!--主管部门-->
                    <div class="form-group row">
                        <label for="department" class="offset-md-1 col-md-2 pt-2">主管部门：</label>
                        <input type="text" v-model="nplant.department" class="form-control col-md-7" name="department" id="department" 
                                    aria-describedby="helpId" placeholder="请输入主管部门" style="background-color: transparent;border: 1px solid black;">
                    </div>

                    <!--保护等级-->
                    <div class="form-group row">
                        <label for="level" class="offset-md-1 col-md-2 pt-2">保护等级：</label>
                        <input type="text" v-model="nplant.level" class="form-control col-md-7" name="level" id="level" 
                                    aria-describedby="helpId" placeholder="请输入保护等级" style="background-color: transparent;border: 1px solid black;">
                    </div>

                    <div class="row pb-3">
                        <button type="button" @click="addnplant()"  class="offset-md-1 col-md-9 btn btn-info btn-lg btn-block">添加国家重点保护植物</button>
                    </div> 
                </form>

                <table class="table table-bordered mt-5" id="tab">
                    <thead>
                        <tr>
                            <th style="border: 1px solid black;">中文名</th>
                            <th style="border: 1px solid black;">拉丁名</th>
                            <th style="border: 1px solid black;">科名</th>
                            <th style="border: 1px solid black;">主管部门</th>
                            <th style="border: 1px solid black;">国家保护等级</th>
                            <th style="border: 1px solid black;">操作</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr v-for="(nplant, index) in nplants" :key="index">
                            <td style="border: 1px solid black;">{{nplant.middlename}}</td>
                            <td style="border: 1px solid black;">{{nplant.latinname}}</td>
                            <td style="border: 1px solid black;">{{nplant.sectionname}}</td>
                            <td style="border: 1px solid black;">{{nplant.department}}</td>
                            <td style="border: 1px solid black;">{{nplant.level}}</td>
                            <td style="border: 1px solid black;">
                                <button v-if="nplant.status==0" class="btn btn-danger" type="button" @click="nplants.splice(index,1)" style=" background-color: #12a4ba;">删除</button>  
                            </td>
                        </tr>
                    </tbody>
                </table>
            </div>
        </div>
    </div>


    <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
  </body>
</html>
<script>
    new Vue({
       el:"#app",
       data() {
           return {
               nplants:nplants,
               nplant:{middlename:"",latinname:"",sectionname:"",department:"",level:"",status:0},
           }
       },
       methods: {
           addnplant(){
               let flag = true;
               let msg = "";
               if(this.nplant.middlename==""){
                   flag = false;
                   msg = "植物中名没有输入，请输入";
               }
               if(this.nplant.latinname==""){
                   flag = false;
                   msg = "植物拉丁名没有输入，请输入";
               }
               if(this.nplant.sectionname==""){
                   flag = false;
                   msg = "植物科名没有输入，请输入";
               }
               if(this.nplant.department==""){
                   flag = false;
                   msg = "植物主管部门没有输入，请输入";
               }
               if(this.nplant.level==""){
                   flag = false;
                   msg = "植物保护等级没有输入，请输入";
               }
               
               if(flag){
                   alert(flag);
                   this.nplants.push(this.nplant);
                   this.clear();
               }else{
                   confirm(msg);
               }
           },
           clear(){
               this.nplant={middlename:"",latinname:"",sectionname:"",department:"",level:"",status:0};
           }
       },
   })
</script>